﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GCELibrary.Current;

using System.Linq.Dynamic;
using System.Linq.Expressions;
using ZF.BLL.Linq;
using ZF.BLL;

namespace ZF.WS.expert
{
    public partial class msg : BLL.Page.PageBase
    {
        [PageArgument(Key = "id", CanNull = false)]
        public int Id { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControls();
            }
        }

        public void InitControls()
        {
            using (var dc = SiteInfo.CreateDBDataContext())
            {
                var list = dc.E_Msg.Where(p => p.RMemberId == Id).ToList();
                this.lvList.DataSource = list.OrderByDescending(p => p.MsgId);
                this.lvList.DataBind();
                var member = SiteInfo.GetCurrentMember();
 
            }
        }

        public void Submit(object sender, EventArgs e)
        {
            using (var dc = SiteInfo.CreateDBDataContext())
            {

                if (!this.vcodeimg1.Check())
                {
                    WarnFactory.CreateWarn(new PageWarnParameter()
                    {
                        JscriptMode = true,
                        Link = WarnLink.GoBack,
                        Message = "验证码错误",
                    }).Alert();
                    return;
                }



                var msg = new Model.E_Msg()
                {
                    AddTime = DateTime.Now,
                    Contact = this.tbContact.Text,
                    CType = this.tbCType.Text,
                    PContent = this.tbContant.Text,
                    RMemberId = Id,
                    Ip = this.Request.UserHostAddress,
                };
                
                try
                {
                    dc.E_Msg.InsertOnSubmit(msg);
                    dc.SubmitChanges();
                }
                catch (Exception ex)
                {
                    throw WarnFactory.CreateWarn(ex);
                }

                WarnFactory.CreateWarn(new PageWarnParameter()
                {
                    JscriptMode = true,
                    Link = WarnLink.Current,
                    Message = "留言成功",
                }).Alert();
            }

        }
    }
}
